<?php

namespace App\Http\Controllers;

use App\Models\Ad;

class AdController extends Controller
{
    public function getAdList()
    {
        $location = request()->input('location', '000000');
        $currentDay = date('Y-m-d');
        $currentTime = date('H:i:s');
        //生成地址array
        $locationArray = ['000000'];
        $locationArray[] = $location;
        $locationArray[] = substr($location, 0, 4) . '00';
        $locationArray[] = substr($location, 0, 2) . '0000';
        $locationArray = array_unique($locationArray);
        //查询
        $list = Ad::whereIn('location', $locationArray)
            ->where('sdate', '<=', $currentDay)
            ->where('edate', '>=', $currentDay)
            ->where('stime', '<=', $currentTime)
            ->where('etime', '>=', $currentTime)
            ->orderBy('sort')
            ->get();
        return response()->json(['recode' => 1, 'list' => $list]);

    }
}
